﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Launcher
{
    /// <summary>
    /// 记录下载字节的位置
    /// </summary>
    public class DownLoadState
    {
        private string _FileName;

        private string _AttachmentName;
        private int _Position;
        private string _RequestURL;
        private string _ResponseURL;
        private int _Length;

        private byte[] _Data;

        public string FileName
        {
            get
            {
                return _FileName;
            }
        }

        public int Position
        {
            get
            {
                return _Position;
            }
        }

        public int Length
        {
            get
            {
                return _Length;
            }
        }


        public string AttachmentName
        {
            get
            {
                return _AttachmentName;
            }
        }

        public string RequestURL
        {
            get
            {
                return _RequestURL;
            }
        }

        public string ResponseURL
        {
            get
            {
                return _ResponseURL;
            }
        }


        public byte[] Data
        {
            get
            {
                return _Data;
            }
        }

        internal DownLoadState(string RequestURL, string ResponseURL, string FileName, string AttachmentName, int Position, int Length, byte[] Data)
        {
            this._FileName = FileName;
            this._RequestURL = RequestURL;
            this._ResponseURL = ResponseURL;
            this._AttachmentName = AttachmentName;
            this._Position = Position;
            this._Data = Data;
            this._Length = Length;
        }

        internal DownLoadState(string RequestURL, string ResponseURL, string FileName, string AttachmentName, int Position, int Length, ThreadCallbackHandler tch)
        {
            this._RequestURL = RequestURL;
            this._ResponseURL = ResponseURL;
            this._FileName = FileName;
            this._AttachmentName = AttachmentName;
            this._Position = Position;
            this._Length = Length;
            this._ThreadCallback = tch;
        }

        internal DownLoadState(string RequestURL, string ResponseURL, string FileName, string AttachmentName, int Position, int Length)
        {
            this._RequestURL = RequestURL;
            this._ResponseURL = ResponseURL;
            this._FileName = FileName;
            this._AttachmentName = AttachmentName;
            this._Position = Position;
            this._Length = Length;
        }

        private ThreadCallbackHandler _ThreadCallback;

        //
        internal void StartDownloadFileChunk()
        {
            if (this._ThreadCallback != null)
            {
                this._ThreadCallback(this._RequestURL, this._FileName, this._Position, this._Length);
            }
        }

    }

    //委托代理线程的所执行的方法签名一致
    public delegate void ThreadCallbackHandler(string S, string s, int I, int i);

    //异常处理动作
    public enum ExceptionActions
    {
        Throw,
        CancelAll,
        Ignore,
        Retry
    }
}
